
package org.example.springbootpra1.demos.bean.enums;

import java.util.stream.Stream;

public enum DeviceTypeEnum {
    TYPE_1("1", "Type 1"),
    TYPE_2("2", "Type 2"),
    TYPE_3("3", "Type 3");

    private final String code;
    private final String description;

    DeviceTypeEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    // 添加一个方法来通过代码获取枚举常量
    public static DeviceTypeEnum fromCode(String code) {
        for (DeviceTypeEnum type : DeviceTypeEnum.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("No enum constant with code: " + code);
    }

}